import 'package:play_android/com/zhihaoliang/http/HttpException.dart';
import 'package:play_android/com/zhihaoliang/base/BaseRepository.dart';
import 'package:play_android/com/zhihaoliang/const/AppApi.dart';
import 'package:play_android/com/zhihaoliang/http/ResultData.dart';
import 'package:play_android/com/zhihaoliang/http/HttpRequest.dart';
import 'package:play_android/com/zhihaoliang/play/hotpage/model/friendsit/FriendSitModel.dart';
import 'package:play_android/com/zhihaoliang/play/hotpage/model/friendsit/FriendSitItem.dart';

///  ***************************************************************************
///  "主页轮训图片"请求处理
///  ***************************************************************************

class FriendSitPresenter extends BaseRepository<List<FriendSitItem>> {
  FriendSitCallBack _callBack;

  FriendSitPresenter(this._callBack);

  load() {
    fetch()
        .then((list) => _callBack.onLoadFriendSitComplete(list))
        .catchError((onError) => _callBack.onLoadFriendSitError(onError));
  }

  @override
  List<FriendSitItem> fetchModel(Map<String, dynamic> map) {
    return FriendSitModel.fromJson(map).data;
  }

  @override
  Future<ResultData> fetchResultData(
      [String url, Map<String, dynamic> map]) async {
    return await HttpRequest().get(AppApi.FRIEND);
  }
}

abstract class FriendSitCallBack {
  void onLoadFriendSitComplete(List<FriendSitItem> list);

  void onLoadFriendSitError(HttpException httpException);
}
